using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InjuredEffect : MonoBehaviour
{
    public float speed;
    public Color injuredColor;
    private SpriteRenderer sr;
    private Color originColor;
    private void Awake()
    {
        sr = GetComponent<SpriteRenderer>();
        originColor = sr.color;
    }

    public void Injured()
    {
        sr.color = injuredColor;
    }

    private void Update()
    {
        if(sr.color!=originColor)
        {
            float r = sr.color.r;
            float g=sr.color.g;
            float b = sr.color.b;
            r += Time.deltaTime * speed * (originColor.r - injuredColor.r);
            g += Time.deltaTime * speed*(originColor.g-injuredColor.g);
            b += Time.deltaTime * speed * (originColor.b - injuredColor.b);
            sr.color = new Color(r, g, b);
        }
    }
}
